#!/usr/bin/python

import bisect, heapq, random, time

X=30000

class qq:
    def __init__(self,a,b):
        self.i=a
        self.j=b
    def __cmp__(self,other):
        return cmp(self.i,other.i)

ctime = time.clock()

# a.1
a=[]
for i in xrange(X):
    a.append(qq(random.random(),random.random()))
#ctime = time.clock()
# b.1
a.sort(lambda x,y:cmp(x.i,y.i))   
# b.2
#a.sort()
# b.1: 0.2s   ----   b.2:  0.9s
print time.clock()-ctime

# a.2
ctime = time.clock()
b=[]
for i in xrange(X):
    bisect.insort(b,qq(random.random(),random.random()))
print time.clock()-ctime

# a.3
ctime = time.clock()
c = []
for i in xrange(X):
    heapq.heappush(c,qq(random.random(),random.random()))
heapq.nlargest(1000,c)
print time.clock()-ctime

# a:   13:36:5
